package com.saodisheng.service.impl;

import com.jfinal.plugin.activerecord.Page;
import com.saodisheng.model.Posts;
import com.saodisheng.service.AccountService;
import com.saodisheng.service.GalleryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * description:
 *
 * @author 扫地生_saodisheng
 * @date 2022/1/29
 */
@Service
public class GalleryServiceImpl implements GalleryService {
	@Autowired
	private AccountService accountService;

	final Posts postsDao = new Posts().dao();
	int pageSize = 12;
	
	@Override
	public List<Posts> getGallery() {
		List<Posts> posts = postsDao.findByCache("gallery", "gallery", "select * from posts where post_type=3 and status=? limit 12", Posts.STATUS_PUB);
		
		return posts;
	}
	
	@Override
	public Page<Posts> getImages(int pageNumber) {
		String select = "select * ";
		String from   = "from posts where post_type=3 and status=?";
		Page<Posts> posts = postsDao.paginate(pageNumber, pageSize, select, from, Posts.STATUS_PUB);
		
		accountService.join("userId", posts.getList(), "nickName", "avatar");
		
		return posts;
	}
}
